package com.education.welco.controller.app;


import com.education.common.core.BaseController;
import com.education.common.utils.ApiReturnObject;
import com.education.welco.pojo.SCatalogMenu;
import com.education.welco.service.ISCatalogMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 教师私有备课目录 信息操作处理
 *
 * @author d
 * @date 2020-05-08
 */
@Api(tags = {"APP-学校课程--目录"})
@RestController
@RequestMapping("/app/sCatalogMenu")
public class AppSCatalogMenuController extends BaseController {

    @Autowired
    private ISCatalogMenuService catalogMenuService;


    @ApiOperation(value = "学校课程--目录接口", httpMethod = "GET")
    @GetMapping("/selectAll")
    public ApiReturnObject selectAll(Integer catalogMenuId) {
        if (catalogMenuId == null){
            return new ApiReturnObject("201","参数为空","参数为空");
        }else {
            Map<String, Object> map = new HashMap<>();
            //根据三级目录查一级目录
            SCatalogMenu oneMenu = catalogMenuService.findByCatalogMenuId(catalogMenuId);
            if (oneMenu == null){
                return new ApiReturnObject("202","查无数据","查无数据");
            }
            //根据一级目录的id查询二级目录
            List<SCatalogMenu> twoMenu = catalogMenuService.findByParentId(oneMenu.getId());
            //根据二级目录id查询三级目录
            for (SCatalogMenu menu : twoMenu) {
                List<SCatalogMenu> threeMenu = catalogMenuService.findByParentId(menu.getId());
                menu.setThreeMenu(threeMenu);
            }
            map.put("menu",twoMenu);
            map.put("oneMenuName",oneMenu.getName());
            map.put("MenuId",oneMenu.getId());
            return new ApiReturnObject("200","查询成功",map);
        }
    }

}